/*************************************************************************
	> File Name: test7.cc
	> Author: H.M. Lau
	> Mail: hm.lau@outlook.com
	> Created Time: 2023/09/19 20:09
 ************************************************************************/

#include <iostream>
#include <signal.h>
#include <cassert>

static void showPending(sigset_t &pending)
{
    for (int sig = 1; sig <= 31; sig++) {
        if (sigismember(&pending, sig)) {
            std::cout << 1;
        } else {
            std::cout << 0;
        }
    }
    std::cout << std::endl;
}

static void blockSig(int sig)
{
    sigset_t bset;
    sigemptyset(&bset);
    sigaddset(&bset, sig);
    int n = sigprocmask(SIG_BLOCK, &bset, nullptr);
    assert(n == 0);
    (void)n;
}

int main(int argc, char *argv[])
{
    for (int sig = 1; sig <= 31; sig++) {
        blockSig(sig);
    }
    sigset_t pending;
    while (1) {
        sigpending(&pending);
        showPending(pending);
        sleep(1);
    }
    return 0;
}
